package com.site.wisdom_construction.controller.qualityModule;

import com.site.wisdom_construction.responseEntity.JsonResult;
import com.site.wisdom_construction.responseEntity.OneDataResult;
import com.site.wisdom_construction.responseEntity.Page;
import com.site.wisdom_construction.service.qualityModule.QualityDangerRecordService;
import com.site.wisdom_construction.util.verification.NoToken;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Author daiyifei
 * @Date 2022/1/11
 * @Description
 */
@Api(tags = "质量隐患记录接口")
@RestController
@RequestMapping("QualityDangerRecord")
@CrossOrigin
public class QualityDangerRecordController {
    @Autowired
    private QualityDangerRecordService qualityDangerRecordService;

    @ApiOperation(value = "增加质量隐患记录信息_PC", notes = "测试数据:")
    @PostMapping("/insertQualityDangerRecordByPc")
    public JsonResult insertSafetyDangerType(@RequestBody Map map){
        JsonResult jsonResult = new JsonResult();
        int i = qualityDangerRecordService.insertQualityDangerRecordByPc(map);
        if (i==1){
            jsonResult.setCode(200);
            jsonResult.setMessage("成功录入质量隐患记录信息!");
        }else {
            jsonResult.setCode(20006);
            jsonResult.setMessage("录入质量隐患记录信息失败!");
        }
        return jsonResult;
    }

    @ApiOperation(value = "增加质量隐患记录信息_APP", notes = "测试数据:")
    @PostMapping("/insertQualityDangerRecordByApp")
    @NoToken
    public JsonResult insertQualityDangerRecordByApp(@RequestBody Map map){
        JsonResult jsonResult = new JsonResult();
        int i = qualityDangerRecordService.insertQualityDangerRecordByApp(map);
        if (i==1){
            jsonResult.setCode(200);
            jsonResult.setMessage("成功录入质量隐患记录信息!");
        }else {
            jsonResult.setCode(20006);
            jsonResult.setMessage("录入质量隐患记录信息失败!");
        }
        return jsonResult;
    }

    @ApiOperation(value = "删除质量隐患记录信息", notes = "测试数据:")
    @PostMapping("/deleteQualityDangerRecord")
    @NoToken
    public JsonResult deleteQualityDangerRecord(@RequestBody Map map){
        JsonResult jsonResult = new JsonResult();
        List<Integer> list = (List<Integer>) map.get("list");
        int l = 0;
        Map mapR = new HashMap();
        for (int i = 0;i<list.size();i++){
            mapR.put("id",list.get(i));
            int a = qualityDangerRecordService.deleteQualityDangerRecord(mapR);
            l+=a;
        }
        if (l>=1){
            jsonResult.setCode(200);
            jsonResult.setMessage("成功删除质量隐患记录信息!");
        }else {
            jsonResult.setCode(20006);
            jsonResult.setMessage("删除质量隐患记录信息失败!");
        }
        return jsonResult;
    }

    @ApiOperation(value = "修改质量隐患记录", notes = "测试数据:")
    @PostMapping("/updateQualityDangerRecord")
    @NoToken
    public JsonResult updateQualityDangerRecord(@RequestBody Map map){
        JsonResult jsonResult = new JsonResult();
        int i = qualityDangerRecordService.updateQualityDangerRecord(map);
        if (i==1){
            jsonResult.setCode(200);
            jsonResult.setMessage("成功修改质量隐患记录信息!");
        }else {
            jsonResult.setCode(20006);
            jsonResult.setMessage("修改质量隐患记录信息失败!");
        }
        return jsonResult;
    }

    @ApiOperation(value = "分页模糊查询质量隐患记录信息", notes = "测试数据:")
    @PostMapping("/findQualityDangerRecordByPage")
    public Page findQualityDangerRecordByPage(@RequestBody Map map) {
        Page page = new Page();
        page.setPageNo((Integer) map.get("pageNo"));
        page.setPageSize((Integer) map.get("pageSize"));
        page.setTotal(qualityDangerRecordService.Total(map));
        page.setItems(qualityDangerRecordService.findQualityDangerRecordByPage(map));
        return page;
    }

    @ApiOperation(value = "查询全部质量隐患记录", notes = "测试数据:")
    @PostMapping("/selectQualityDangerRecord")
    @NoToken
    public OneDataResult selectQualityDangerRecord(@RequestBody Map map) {
        OneDataResult oneDataResult = new OneDataResult();
        oneDataResult.setData(qualityDangerRecordService.selectQualityDangerRecord(map));
        return oneDataResult;
    }

    @ApiOperation(value = "根据id查询质量隐患记录", notes = "测试数据:")
    @PostMapping("/findQualityDangerRecordById")
    public OneDataResult findQualityDangerRecordById(@RequestBody Map map) {
        OneDataResult oneDataResult = new OneDataResult();
        oneDataResult.setData(qualityDangerRecordService.findQualityDangerRecordById(map));
        return oneDataResult;
    }

    @ApiOperation(value = "查询对应安管人员上传的质量隐患记录", notes = "测试数据:")
    @PostMapping("/findSafetyDangerRecordByManagerialId")
    @NoToken
    public Page findSafetyDangerRecordByManagerialId(@RequestBody Map map) {
        Page page = new Page();
        page.setPageNo((Integer) map.get("pageNo"));
        page.setPageSize((Integer) map.get("pageSize"));
        page.setTotal(qualityDangerRecordService.totalByManagerialId(map));
        page.setItems(qualityDangerRecordService.findQualityDangerRecordByByManagerialId(map));
        return page;
    }

    @ApiOperation(value = "整改上报", notes = "测试数据:")
    @PostMapping("/updateQualityDangerRecordByReport")
    @NoToken
    public JsonResult updateQualityDangerRecordByReport(@RequestBody Map map){
        JsonResult jsonResult = new JsonResult();
        int i = qualityDangerRecordService.updateQualityDangerRecordByReport(map);
        if (i==1){
            jsonResult.setCode(200);
            jsonResult.setMessage("整改上报成功!");
        }else {
            jsonResult.setCode(20006);
            jsonResult.setMessage("整改上报失败!");
        }
        return jsonResult;
    }


    @ApiOperation(value = "整改验收", notes = "测试数据:")
    @PostMapping("/updateQualityDangerRecordAccept")
    @NoToken
    public JsonResult updateQualityDangerRecordAccept(@RequestBody Map map){
        JsonResult jsonResult = new JsonResult();
        int i = qualityDangerRecordService.updateQualityDangerRecordAccept(map);
        if (i==1){
            jsonResult.setCode(200);
            jsonResult.setMessage("整改验收成功!");
        }else {
            jsonResult.setCode(20006);
            jsonResult.setMessage("整改验收失败!");
        }
        return jsonResult;
    }

    @ApiOperation(value = "查询劳务人员对应的安全隐患记录", notes = "测试数据:")
    @PostMapping("/findQualityDangerRecordByByWorkersId")
    @NoToken
    public Page findQualityDangerRecordByByWorkersId(@RequestBody Map map) {
        Page page = new Page();
        page.setPageNo((Integer) map.get("pageNo"));
        page.setPageSize((Integer) map.get("pageSize"));
        page.setTotal(qualityDangerRecordService.totalByWorkersId(map));
        page.setItems(qualityDangerRecordService.findQualityDangerRecordByByWorkersId(map));
        return page;
    }
}
